#pragma once
#include "oxtreectrl.h"
#include "OXLayoutManager.h"
#include "draw_obj.h"


// CROIDlg dialog

class CROIDlg : public CDialogEx
{
	DECLARE_DYNAMIC(CROIDlg)

public:
	CROIDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CROIDlg();

// Dialog Data
	enum { IDD = IDD_ROI_PANE };

public:
  void ObjAdd_slot(const draw_obj* obj);
  void ObjDelete_slot(const draw_obj* obj);
  void ObjEdit_slot(const draw_obj* obj);
  void ObjSelect_slot(const draw_obj* obj);
  void ObjDeselect_slot(const draw_obj* obj);

public:
  HTREEITEM FindTreeItem(DWORD data);
  bool IsFamilyItemSelected(HTREEITEM hParent);
  void ChangeName(DWORD data, const tstring& newName);

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
public:
  afx_msg void OnBnClickedOk();
  afx_msg void OnBnClickedCancel();
  afx_msg void OnDestroy();
  afx_msg void OnObjListItemChanged(NMHDR *pNMHDR, LRESULT *pResult);
  afx_msg void OnObjListItemActivate(NMHDR *pNMHDR, LRESULT *pResult);
  afx_msg void OnObjListColumnClick(NMHDR *pNMHDR, LRESULT *pResult);
  afx_msg void OnObjListStateChanged(NMHDR *pNMHDR, LRESULT *pResult);
  afx_msg void OnObjListEndEdit(NMHDR *pNMHDR, LRESULT *pResult);
  afx_msg void OnObjListMarqueeBegin(NMHDR *pNMHDR, LRESULT *pResult);
  virtual BOOL OnInitDialog();

public:
  COXTreeCtrl       drawobj_list_;
  COXLayoutManager  layout_manager_;
  BOOL disableStateChangeNotifyHandler;
  boost::signals2::connection objSelectSignalConnection;
};

class ObjAddVisitor : public boost::static_visitor<void>
{
public:

  ObjAddVisitor(const draw_obj* obj, COXTreeCtrl& obj_list)
    : obj_(obj)
    , obj_list_(obj_list)
  {
  }

  ~ObjAddVisitor(void)
  {
  }

public:

  void operator()(const point_2& point) const;
  void operator()(const segment_2& segment) const;
  void operator()(const box_2& box) const;
  void operator()(const angle_box_2& angle_box) const;
  void operator()(const ring_2& ring) const;
  void operator()(const arc_2& arc) const;
  void operator()(const annulus_2& annulus) const;
  void operator()(const annulus_arc_2& annulus_arc) const;
  void operator()(const polygon_2& polygon) const;

private:
  const draw_obj*      obj_;
  COXTreeCtrl&         obj_list_;
};

class ObjEditVisitor : public boost::static_visitor<void>
{
public:

  ObjEditVisitor(HTREEITEM hitem, COXTreeCtrl& obj_list)
    : hitem_(hitem)
    , obj_list_(obj_list)
  {
  }

  ~ObjEditVisitor(void)
  {
  }

public:

  void operator()(const point_2& point) const;
  void operator()(const segment_2& segment) const;
  void operator()(const box_2& box) const;
  void operator()(const angle_box_2& angle_box) const;
  void operator()(const ring_2& ring) const;
  void operator()(const arc_2& arc) const;
  void operator()(const annulus_2& annulus) const;
  void operator()(const annulus_arc_2& annulus_arc) const;
  void operator()(const polygon_2& polygon) const;

private:
  HTREEITEM     hitem_;
  COXTreeCtrl&  obj_list_;
};